package com.shoparc.mvc;

import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PVector;

public class ViewFrame extends PApplet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1770379962416342562L;
	
	
	

	protected Controller controller;
	public int w;
	public int h;
	public PFont defaultfont0 = createFont("ProggyCleanTTSZ", 50);
	
	//Camera variables
	float currentZ = 0;
	protected float Ctheta = (float) 180;
	protected float Czeta = (float) 0.06539816;
	protected PVector target = new PVector(0, 0, 0);
	PVector old_camera_pos = new PVector(-100, 0, -100);
	public float zoom = 50;
	
	
	public static void main(String args[]) {
		PApplet.main(new String[] { "--present",
				"com.shoparc.mvc.ViewFrame" });
	}
	
	public void setup(){
		//controller = new Controller(this);
		//controller.setup();


		size(1680, 1050, P3D);
		
		
	}
	
	public void draw(){
		background(255);
		controller.camVarUpdate();
		controller.keycontrol();
		cameraControls(Ctheta, Czeta, target, zoom);
	}
	
	public void drawPersp() {
		camera();
		perspective();
	}

	public void drawOrtho() {
		camera();

		cameraControls(Ctheta, Czeta, target, zoom);
	}
	
	protected void cameraControls(float _Ctheta, float _Czeta, PVector _target,
			float _distance) {

		perspective(PI / 3, (float) 1.33, (height / 2) / tan(PI * 60 / 360)
				/ 100, (height / 2) / tan(PI * 60 / 360) * 10);

		// ortho(-zoom, zoom, -zoom, zoom, -1000, 1000);
		PVector camera_pos = new PVector(0, 0, 0);
		camera_pos.z = _distance * sin(_Czeta) + _target.z;
		float lil_d = (camera_pos.z - _target.z) / tan(_Czeta);
		camera_pos.x = lil_d * cos(_Ctheta) + _target.x;
		camera_pos.y = lil_d * sin(_Ctheta) + _target.y;
		camera(camera_pos.x, camera_pos.y, camera_pos.z, // eyeX, eyeY, eyeZ
				_target.x, _target.y, _target.z, // centerX, centerY, centerZ
				0, 0, -1);

	}
	
	protected void test(){
		stroke(255,0,0);
		ellipse(10,10,10,10);
	}
	

}
